package tutorial.java.dragdrop;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JOptionPane;
import javax.swing.JRadioButton;
import javax.swing.ButtonGroup;
import javax.swing.JButton;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class RadioButtonDemo extends JFrame {

	private JPanel contentPane;
	private JRadioButton rdbtVietnam;
	private JRadioButton rdbtThailan;
	private JRadioButton rdbtEngland;
	private final ButtonGroup buttonGroup = new ButtonGroup();

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					RadioButtonDemo frame = new RadioButtonDemo();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public RadioButtonDemo() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		setResizable(false);
		setLocationRelativeTo(null);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		rdbtVietnam = new JRadioButton("Viet Nam");
		buttonGroup.add(rdbtVietnam);
		rdbtVietnam.setBounds(128, 39, 109, 23);
		contentPane.add(rdbtVietnam);
		
		rdbtThailan = new JRadioButton("Thai Lan");
		buttonGroup.add(rdbtThailan);
		rdbtThailan.setBounds(128, 86, 109, 23);
		contentPane.add(rdbtThailan);
		
		rdbtEngland = new JRadioButton("England");
		buttonGroup.add(rdbtEngland);
		rdbtEngland.setBounds(128, 135, 109, 23);
		contentPane.add(rdbtEngland);
		
		JButton btnSave = new JButton("Save");
		btnSave.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				if (rdbtVietnam.isSelected()) {
					JOptionPane.showMessageDialog(null, "This is Viet Nam");
				}
				if (rdbtThailan.isSelected()) {
					JOptionPane.showMessageDialog(null, "This is Thai Lan");
				}
				if (rdbtEngland.isSelected()) {
					JOptionPane.showMessageDialog(null, "This is England");
				}
			}
		});
		btnSave.setBounds(131, 189, 89, 23);
		contentPane.add(btnSave);
	}
}
